//
//  SJ_SingletonValue.m
//  Goddess
//
//  Created by bigbang进哥哥 on 17/4/25.
//  Copyright © 2017年 bigbang进哥哥. All rights reserved.
//

#import "SJ_SingletonValue.h"

static SJ_SingletonValue *singleton = nil;

@implementation SJ_SingletonValue

//实现方法,判断是否为空,是就创建一个全局实例给它
+ (SJ_SingletonValue *)singleton {
    
    if (singleton == nil) {
        singleton = [[SJ_SingletonValue alloc] init];
    }
    return singleton;
}

//避免alloc/new创建新的实例变量--->增加一个互斥锁
+ (id)allocWithZone:(struct _NSZone *)zone {
    
    @synchronized(self) {
        if (singleton == nil) {
            singleton = [super allocWithZone:zone];
        }
    }
    return singleton;
}

//避免copy,需要实现NSCopying协议
- (id)copyWithZone:(NSZone *)zone {
    return self;
}
-(id)mutableCopyWithZone:(NSZone *)zone
{
    return self;
}

@end
